/**
 * 
 */
package game.rwalk.entity;

import game.rwalk.utility.Constants;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;

/**
 * @author sk8erboi
 *
 */
public class Row {
	
	public ArrayList<Cell> cells = new ArrayList<Cell>();
	private int yRow;
	private int hitColor, hitCell;
	private Rect scope;
	
	public boolean hit = false;
	
	//define state of row
	public boolean isActive = true;

	//constructor
	public Row(int[] ids, int[] index, Context mContex) {
		
		//add cell into cells arraylist
		for(int i = 0; i< Constants.NUMBER_CELL; i++) {
			cells.add(new Cell(ids, index[i], mContex));
		}
		
		init();
	}
	
	//define left & right of rect cell
	private void init() {
		for(int i = 0; i < Constants.NUMBER_CELL; i++) {
			cells.get(i).getScope().set(Constants.MARGIN_WIDTH + i*Constants.WIDTH_CELL,
										 0,
										 Constants.MARGIN_WIDTH + (i + 1)*Constants.WIDTH_CELL,
										 50
										);
		}
	}
	
	//onDraw : 
	public void onDraw(Canvas canvas, int y, Paint bitmapPaint) {
		
		//
		for(int i = 0; i < Constants.NUMBER_CELL; i++) {
			canvas.drawBitmap(cells.get(i).bitmap,
								Constants.MARGIN_WIDTH + Constants.LEFT_CELL + i*Constants.WIDTH_CELL,
								Constants.TOP_CELL + y,
								bitmapPaint
							  );
		}
	}
	
	public void hitCell(int x) {
		for(int i = 0; i < Constants.NUMBER_CELL; i++) {
			if((x >= cells.get(i).getScope().left) && (x <= cells.get(i).getScope().right)) {
				
				//set hit to true
				hit = true;
				
				cells.get(i).changeActiveColor(true);
				hitColor = cells.get(i).getColor();
				hitCell = i;
				break;
			} else {
				hit = false;
			}
		}
	}
	
	public void reset() {
		cells.get(hitCell).changeActiveColor(false);
		isActive = true;
	}
	
	public int getyRow() {
		return yRow;
	}

	public void setyRow(int yRow) {
		this.yRow = yRow;
	}
	
	public int getHitColor() {
		return hitColor;
	}
	
	public Rect getScope() {
		return scope;
	}

	public void setScope(Rect scope) {
		this.scope = scope;
	}
}
